﻿using System;
using System.Net;
using System.Net.Sockets;
using System.IO;
using System.Threading;
using System.Collections.Generic;
/*
* This program establishes a connection to irc server, joins a channel .
*
*
*/
namespace IRCTest
{

    class Program
    {
        
        private static Thread BotThread;
        private static IRCBot Bot;
        static void Main(string[] args)
        {
            //D Functie = new D(Test);
          
            /*List<String> Leaders = new List<String>();
            Leaders.Add("Daneo");
            Leaders.Add("Padraig");
            GetData GetData = new GetData("http://ts2.travian.nl/map.sql",Leaders);
            Thread.Sleep(20000);*/
            Bot = new IRCBot("Falco","Sk0tchParuche","Falco","#Druids.pub","#DRUIDS");
           
            Bot.onMessageReceived += new IRCMEvent(HandleMessage);
            Bot.onUserEvent += new IRCUEvent(UserAction);
            Bot.onCommand += new IRCCEvent(CommandReceived);
            Bot.onBasicEvent += new IRCBEvent(BasicEventReceived);
            Bot.onUserCheck += new IRCListEvent(Bot_onUserCheck);
            BotThread = new Thread(new ThreadStart(Bot.RUN));
            BotThread.Start();
            
        }

        static void Bot_onUserCheck(object IRCBotInstance, IRCUserList ListEvent)
        {
            foreach (String User in  ListEvent.Users)
            {
                Console.WriteLine(User);
            }
        }

        static void BasicEventReceived(object IRCBotInstance, IRCBasicEvent IRCEvent)
        {
            Console.WriteLine(IRCEvent.Line);
        }
        
        static void CommandReceived(object IRCBotInstance, IRCCommandEvent Command)
        {
            Bot.Actions.Send_Message2(Command.CommandName + " is about to be implemented.", Command.Channel);
        }

        public static void UserAction(object IRCBotInstance, IRCUserEvent UserLeft)
        {
            if (UserLeft.Joined)
                Bot.Actions.Emote("welcomes " + UserLeft.User + " warmly.", UserLeft.Channel);
            else
                Bot.Actions.Emote("says goodbye to " + UserLeft.User + "!", UserLeft.Channel);
        }

        public static void HandleMessage(object IRCBotInstance, IRCMessageEvent Message)
        {

            if ((Message.Line.Equals(":NickServ!irc@traviangames.org NOTICE Falco :If you do not change within one minute, I will change your nick.")))
            {
                Bot.Kill_Ghost();
                Bot.Identify();
                Bot.Ask_inv();
                Thread.Sleep(750);  

                Bot.Join_Chan();
                Bot.Join_Chan();
                Bot.GetUsers("#Druids");
                //Bot.Actions.Send_Message("/who " + Bot.Actions.Channel,Bot.,);
            }
            System.Console.WriteLine(Message.Line);
        }

        
         
    }
}